package com.mooc.lib_video.adapter

import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.mooc.ijk.widget.IJKView
import com.mooc.lib_network.imgload.ImageLoad
import com.mooc.lib_video.R
import com.mooc.lib_video.model.CommentsEntity
import com.tb.emoji.EmojiUtil
import java.io.IOException

class CommentsAdapter : BaseQuickAdapter<CommentsEntity,BaseViewHolder>(R.layout.layout_feed_comment_list_item) {

    init {
        addChildClickViewIds(R.id.video_icon)
    }

    override fun convert(holder: BaseViewHolder, item: CommentsEntity) {
        var avatar = holder.getView<ImageView>(R.id.author_avatar)
        ImageLoad.loadMatch(item.author!!.avatar,avatar)
        holder.setText(R.id.author_name,item.author!!.name)
        holder.setText(R.id.create_time, TimeUtils.millis2String(item.createTime))
        val comment_text : TextView = holder.getView(R.id.comment_text)
        holder.setText(R.id.comment_text,item.commentText)
        try {
            EmojiUtil.handlerEmojiText(comment_text, comment_text.getText().toString(), context)
        } catch (e: IOException) {
            e.printStackTrace()
        }
        if (item.commentType==1){
            //文字
            holder.setVisible(R.id.comment_ext, false)
        }else if (item.commentType == 2){
            //图片
            holder.setVisible(R.id.comment_ext, true)
            holder.setVisible(R.id.detail_item_player,false)
            holder.setVisible(R.id.comment_cover,true)
            holder.setVisible(R.id.video_icon,false)
            val img = holder.getView<ImageView>(R.id.comment_cover)
            ImageLoad.loadMatch(item.imageUrl,img)
        }else if (item.commentType == 3){
            //视频
            holder.setVisible(R.id.comment_ext, true)
            holder.setVisible(R.id.comment_cover,false)
            holder.setVisible(R.id.detail_item_player,true)
            holder.setVisible(R.id.video_icon,true)
            val ijk : IJKView = holder.getView(R.id.detail_item_player)
            ijk.setConverPath(item.imageUrl)
        }
    }
}